package com.hsj.ribbon.controller;

import com.hsj.ribbon.service.RibbonService;
import dto.TransData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import pojo.User;

/**
 * @author:Teacher黄
 * @date:Created at 2020/01/01
 */
@RestController
public class RibbonController {

    @Autowired
    private RestTemplate restTemplate;


    @GetMapping("/ribbon/consumer")
    public String helloConsumer(){
        // 消费服务
        String forObject = restTemplate.getForObject("http://SERVICE01/service01/hello", String.class);
        return forObject;
    }


    @GetMapping("/ribbon/get/{userName}")
    public TransData consumerGet(@PathVariable String userName){
        return restTemplate.getForObject("http://SERVICE01/service01/get/{userName}", TransData.class, userName);
    }


    @PostMapping("/ribbon/post")
    public TransData consumerPost(String userName){
        return restTemplate.postForObject("http://SERVICE01/service01/post",userName,TransData.class);
    }

    @PostMapping("/ribbon/user")
    public TransData consumerPost(){
        User user = new User();
        user.setUserName("哈哈");
        return restTemplate.postForObject("http://SERVICE01/service01/user",user,TransData.class);
    }

    @Autowired
    private RibbonService ribbonService;

    @PostMapping("/ribbon/user1")
    public TransData consumerPost1(){
       return ribbonService.postUser();
    }

}
